home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d13
/
rep504.arc
/
REPLACE.DOC
< prev
Wrap
Text File
|
1991-04-16
|
18KB
|
537 lines
================================================================
| REPLACE Version 5.04 1987-91 (C) Gene Garapic Cleveland Ohio |
================================================================
Comes AS-IS with no warranty - May be freely distributed
=========================
| What does REPLACE do? |
=========================
REPLACE searches a file for a specified string and if found replaces it
with another specified string continuing until the whole file is processed
=========================
| Special Features |
=========================
Run REPLACE many times in a batch file using different parameters to get
almost any desired result. See advanced user switches (Detail 2)
=========================
| Getting Started |
=========================
Use MS DOS 2.00 up
See Detail 1
Run REPLACE [filename] [find] [replace]
Hint: Run REPLACE without parameters to display brief instruction set
=========================
| Detail 1.0 Set PATH |
=========================
Set PATH so REPLACE can be found from any subdirectory
Here is an example of a set PATH command line in your AUTOEXEC.BAT file
PATH=C:\DOSFILES;C:\GENE
Replace.com, Replace.doc and Repxxx.zip would be in subdirectory GENE
================================================
| Detail 1.1 REPLACE.COM command line syntax |
================================================
The normal DOS command line syntax is:
REPLACE [filename] [find] [replace]
Examples:
REPLACE [filename] 13,10 13,10,13,10 <-Double space all single spaced lines
REPLACE [filename] 13,10,13,10 13,10 <-Single space all double spaced lines
REPLACE [filename] 13,10 13,10,9,9 <-Tab all lines twice for hole punch
REPLACE [filename] "hello" "goodby" <-Find hello replace with goodby
REPLACE [filename] "hello" "" <-Find hello and delete with null ("")
Find string can not be null (""), replace string can
Comma (,) delimits decimal (0-255) ASCII codes
Quotation mark (") delimits ASCII character strings
The orginal file is renamed with a BAK extension
The new file takes on the name of the original file
Returns to the DOS command line prompt when done
Tech Notes: 13 decimal equals a carriage return
10 decimal equals a line feed
9 decimal equals a tab
========================================================
| Detail 2.0 Special advanced user function switches |
========================================================
You should be able to find uses for some of these switches
Please try these switches on small test (junk) files first
Detail 2.1.1 /F Makes file of lines containing [string]
Detail 2.1.2 /F- Makes file of lines NOT containing [string] (new 1991)
Detail 2.2 /P Pad with spaces from code 1 to [column]
Detail 2.3 /C Cut between columns [c1] [c2] inclusive
Detail 2.4 /E Expand tabs in [file1] with spaces to [file2]
Detail 2.5 /R Return key press upper case decimal errorlevel
Detail 2.6 /A Act on column with wildcards (?) allowed
Detail 2.7 /N Number all lines in an ASCII text file
Detail 2.8 /M Return month to batch file as errorlevel (1-12)
Note: Use only one switch at a time for each REPLACE run
============================
| Detail 2.1.1 /F switch |
============================
REPLACE [filename] [string] /F
Makes a file of only the lines containing [string]
This function is something like your FIND.EXE DOS utility
Example:
Below is portion of REPLACE.ASM file before action:
----------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
REPLACE REPLACE.ASM "ASSUME" /F
Note: Above line was keyed in on DOS command line to start action
Below is REPLACE.ASM file after action:
---------------------------------------------
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
Note: Only lines containing ASSUME are now in REPLACE.ASM file
=============================
| Detail 2.1.2 /F- switch |
=============================
REPLACE [filename] [string] /F-
Makes a file of only the lines NOT containing [string]
This function is something like your FIND.EXE DOS utility
Example:
Below is portion of REPLACE.ASM file before action:
----------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
REPLACE REPLACE.ASM "ASSUME" /F-
Note: Above line was keyed in on DOS command line to start action
Below is REPLACE.ASM file after action:
---------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ORG 100H
Note: Only lines NOT containing ASSUME are now in REPLACE.ASM file
==========================
| Detail 2.2 /P switch |
==========================
REPLACE [filename] 1 "" /P[column]
Pads lines with spaces from code 1 to specified [column]
Note: First run REPLACE to insert the 1 code
Then run REPLACE with the /P switch
Example:
Below is portion of REPLACE.ASM file before action:
----------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
START: JMP BEGIN ;
OUT_PTR DW 0 ; Used by all
PAD_FLAG DB 0 ; Pad function
CUT_FLAG DB 0 ; Cut between columns
ERR_FLAG DB 0 ; Return with error function
EXP_FLAG DB 0 ; Expand Tabs with Spaces
Note: Semicolons (;) in lines do not line up
REPLACE REPLACE.ASM ";" 1,";"
Note: Above line was keyed in on DOS command line to start action
REPLACE is NOT using any special switches yet
Below is portion of REPLACE.ASM file after action:
---------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
START: JMP BEGIN ;
OUT_PTR DW 0 ; Used by all
PAD_FLAG DB 0 ; Pad function
CUT_FLAG DB 0 ; Cut between columns
ERR_FLAG DB 0 ; Return with error function
EXP_FLAG DB 0 ; Expand Tabs with Spaces
Note: 1 code displays as a character
Note: Now use /P switch to complete the job
Example continued:
REPLACE REPLACE.ASM 1 "" /P37
Note: Above line was keyed in on DOS command line to start action
Below is portion of REPLACE.ASM file after action:
---------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
START: JMP BEGIN ;
OUT_PTR DW 0 ; Used by all
PAD_FLAG DB 0 ; Pad function
CUT_FLAG DB 0 ; Cut between columns
ERR_FLAG DB 0 ; Return with error function
EXP_FLAG DB 0 ; Expand Tabs with Spaces
Note: All the semicolons (;) now line up at column 37
Note: Pads all 1 coded lines but only one 1 code () left indexed per run.
In other words if there are three 1 codes () per line then REPLACE
with /P switch must be run three times to complete job. To find out
how many times to run REPLACE with the /P switch look at ASCII text
and count the 1 codes ( face characters) in one line
Note: If 1 code is at line column greater then [column] then no action taken
Note: If you use the /P switch you are a VERY advanced user!
==========================
| Detail 2.3 /C switch |
==========================
REPLACE [filename] [c1] [c2] /C
Cuts text from all lines in [filename] between columns [c1] [c2] inclusive
Example:
Below is portion of REPLACE.ASM file before action:
----------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
START: JMP BEGIN ;
OUT_PTR DW 0 ; Used by all
PAD_FLAG DB 0 ; Pad function
CUT_FLAG DB 0 ; Cut between columns
ERR_FLAG DB 0 ; Return with error function
EXP_FLAG DB 0 ; Expand Tabs with Spaces
Note: That there is text past column 37 on most lines
REPLACE REPLACE.ASM 37 80 /C
Note: Above was keyed in on DOS command to start action
Below is portion of REPLACE.ASM file after action:
---------------------------------------------
PAGE ,132
TITLE REPLACE Version 2.08.22 1987
CODE SEGMENT
ASSUME CS:CODE,SS:CODE
ASSUME DS:CODE,ES:CODE
ORG 100H
START: JMP BEGIN
OUT_PTR DW 0
PAD_FLAG DB 0
CUT_FLAG DB 0
ERR_FLAG DB 0
EXP_FLAG DB 0
Note: Everything from column 37 thru 80 has been deleted (Cut) from file
==========================
| Detail 2.4 /E switch |
==========================
REPLACE [file1] /E >[file2]
Expand Tabs in [file1] with Spaces to [file2]
Reason for using /E is that it makes ASCII files SORT.EXE compatible.
When sorting on columns SORT is fooled by files with tabs and does not
give proper results. /E puts in spaces to the proper column when it
encounters tab (9) code making the file columns true as far as SORT is
concerned. You will use SORT on the new file [file2]
Example:
REPLACE REPLACE.ASM /E >REPLACE2.ASM
Note: Above line was keyed in at the DOS prompt
There is disk activity but no screen action
Returns to DOS prompt when done
An ASCII editor verifies REPLACE2.ASM file has spaces instead of tabs
==========================
| Detail 2.5 /R switch |
==========================
REPLACE /R
Returns user alpha key press in upper case decimal as error code
for batch file processing
Example 1:
REPLACE /R
Waits for a key press.
If "A" or "a" is pressed then decimal 65 (A) is returned to
your batch file as an error code for your batch file to process
Example 2:
REPLACE /R
Waits for a key press.
If "Z" or "z" is pressed then decimal 90 (Z) is returned to
your batch file as an error code for your batch file to process
Note: Letters in between return their unique upper case code
Note: Cut and Paste below example to file RTEST.BAT for demo
echo off
cls
echo This is a demo using the REPLACE /R switch in a batch file
echo .
:MENU
echo ====================================================================
echo MENU
echo Press key for [function]
echo .
echo A [function] B [function] C [function] D [function] E [function]
echo F [function] G [function] H [function] I [function] J [function]
echo .
echo Press Esc key to exit RTEST demo
echo .
echo Also try keys not shown in menu
echo Wait a few seconds for batch file to respond
echo ====================================================================
REPLACE /R Loads to get key press then returns to this batch file below
rem Highest errorlevel always tested first by DOS batch processor
rem 90 (Z or z) is highest legal key press in this example
if errorlevel 91 goto GREATER
if errorlevel 75 goto NOFUNCT
if errorlevel 74 goto J
if errorlevel 73 goto I
if errorlevel 72 goto H
if errorlevel 71 goto G
if errorlevel 70 goto F
if errorlevel 69 goto E
if errorlevel 68 goto D
if errorlevel 67 goto C
if errorlevel 66 goto B
if errorlevel 65 goto A
if errorlevel 28 goto LESS
if errorlevel 27 goto ESC Only legal key press below 65 in RTEST demo
if errorlevel 1 goto LESS
if errorlevel 0 goto ABORT
:A
echo "A" or "a" was pressed so do it's [function] here
goto MENU
:B
echo "B" or "b" was pressed so do it's [function] here
goto MENU
:C
echo "C" or "c" was pressed so do it's [function] here
goto MENU
:D
echo "D" or "d" was pressed so do it's [function] here
goto MENU
:E
echo "E" or "e" was pressed so do it's [function] here
goto MENU
:F
echo "F" or "f" was pressed so do it's [function] here
goto MENU
:G
echo "G" or "g" was pressed so do it's [function] here
goto MENU
:H
echo "H" or "h" was pressed so do it's [function] here
goto MENU
:I
echo "I" or "i" was pressed so do it's [function] here
goto MENU
:J
echo "J" or "j" was pressed so do it's [function] here
goto MENU
:NOFUNCT
echo Errorlevel 75 through 90 has no [function] assigned in RTEST demo
goto MENU
:GREATER
echo Errorlevel greater then 90 decimal is not legal in RTEST demo
goto MENU
:LESS
echo Errorlevel less then 65 decimal is not legal in RTEST demo
goto MENU
:ABORT
echo .
echo Errorlevel is 0 so aborting
echo .
echo Possible cause is REPLACE.COM missing
goto end
:ESC
echo .
echo Esc key was pressed
:end
==========================
| Detail 2.6 /A switch. |
==========================
Note: Wildcards are allowed when using the /A switch
REPLACE [filename] [find?] [replace] /A[column]
Find and replace at [column] with wildcards (?) allowed in [find] string
Example of /A switch with a file named TEST.TXT
Before action
REPLACE ASM 53695 8-22-88 7:56a
R-TUP BAT 167 8-22-88 9:14a
REPLACE COM 4593 8-22-88 7:57a
REPLACE DOC 16109 8-22-88 9:13a
REPLACE TEST.TXT "-??" "-90" /A29
Note: Above keyed in on DOS command line
After action
REPLACE ASM 53695 8-22-90 7:56a
R-TUP BAT 167 8-22-90 9:14a
REPLACE COM 4593 8-22-90 7:57a
REPLACE DOC 16109 8-22-90 9:13a
Note: ---- Column 29 ---->^
Note: "-??" would include "-22" in find string but "-22" starts before
column 29 therefore is not effected by replace string and only
"-88" is replaced with "-90" in each line
Note: Wildcards need not be used with /A switch
Note: /A with no [column] starts action at beginning of line and does
the complete line instead of just at the specified column
Note: If you use the /A switch you are a VERY advanced user!
==========================
| Detail 2.7 /N switch |
==========================
REPLACE [filename] /N
Number all lines in an ASCII text file
Text file lines must be terminated with Carriage Return and Line Feed
Example of /N switch with a file named LN.ASM
Selected portion before action
;---------------------------------------;
PAGE ,132 ;
VER EQU ' Version 1.07.01 ' ;
CODE SEGMENT ;
ASSUME CS:CODE,SS:CODE ;
ASSUME DS:CODE,ES:CODE ;
ORG 100H ;
;---------------------------------------;
START: JMP DO_LINE_NUMBER ;
REPLACE LN.ASM /N
Note: Above keyed in DOS command line
Selected portion after action
1 ;---------------------------------------;
2 PAGE ,132 ;
3 VER EQU ' Version 1.07.01 ' ;
4 CODE SEGMENT ;
5 ASSUME CS:CODE,SS:CODE ;
6 ASSUME DS:CODE,ES:CODE ;
7 ORG 100H ;
8 ;---------------------------------------;
9 START: JMP DO_LINE_NUMBER ;
==========================
| Detail 2.8 /M switch |
==========================
REPLACE /M
Return month to batch file as errorlevel (1-12)
Below is a demo batch file named M.BAT
echo off
cls
REPLACE /M
if errorlevel 12 goto DEC
if errorlevel 11 goto NOV
if errorlevel 10 goto OCT
if errorlevel 9 goto SEP
if errorlevel 8 goto AUG
if errorlevel 7 goto JUL
if errorlevel 6 goto JUN
if errorlevel 5 goto MAY
if errorlevel 4 goto APR
if errorlevel 3 goto MAR
if errorlevel 2 goto FEB
if errorlevel 1 goto JAN
:DEC
echo December
goto endM
:NOV
echo November
goto endM
:OCT
echo October
goto endM
:SEP
echo September
goto endM
:AUG
echo August
goto endM
:JUL
echo July
goto endM
:JUN
echo June
goto endM
:MAY
echo May
goto endM
:APR
echo April
goto endM
:MAR
echo March
goto endM
:FEB
echo February
goto endM
:JAN
echo January
:endM
Note: You must have Clock/Calendar or set DATE for accurate result
===========================
| Detail 3.0 Uploading |
===========================
If uploading Rep504.zip to BBSes please use comment line as shown below
Garapic's search and replace plus
====================
| End REPLACE.DOC |
====================